<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(\App\Models\Team::class, 10)->create();

        \App\Models\Team::all()->each(function (\App\Models\Team $team) {
            factory(\App\Models\User::class, random_int(10,20))->create(['team_id' => $team->id]);
            factory(\App\Models\TeamLeader::class, 1)->create(['team_id' => $team->id]);
            factory(\App\Models\User::class, 10)->create()->each(function (\App\Models\User $user) use ($team) {
               \App\Models\Apply::create(['user_id' => $user->id, 'team_id' => $team->id]);
            });

        });

        factory(\App\Models\Product::class, 5)->create()->each(function (\App\Models\Product $product) {
            factory(\App\Models\ProductSku::class, 3)->create(['product_id' => $product->id, 'price' => $product->price]);
        });

        factory(\App\Models\Administrator::class, 3)->create()->each(function (\App\Models\Administrator $operator) {
            $operator->roles()->save(\Encore\Admin\Auth\Database\Role::find(2));
            factory(\App\Models\Machine::class, 3)->create(['operator_id' => $operator->id]);
        });
    }
}
